<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:template match="Class">
		<xsl:variable name="Name" select="Name"/>
		

PRINT 'Working on ActiveRecord object [<xsl:value-of select="Name"/>]'


DROP TABLE [<xsl:value-of select="Name"/>]
GO

CREATE TABLE [<xsl:value-of select="Name"/>] (
	[ObjectID] [uniqueidentifier] NOT NULL,
	[Modified] [datetime] NOT NULL,
		<xsl:for-each select="ClassAttribs/ClassAttributes">
			<xsl:if test="CType='single'">
	[<xsl:value-of select="Name"/>] <xsl:value-of select="SqlType"/> NULL,
			</xsl:if>
		</xsl:for-each>
	CONSTRAINT [PK_<xsl:value-of select="Name"/>] PRIMARY KEY CLUSTERED ( [ObjectID] ) ON [PRIMARY]
) ON [PRIMARY]
GO





		<xsl:for-each select="ClassAttribs/ClassAttributes">
			<xsl:if test="CType='array'">
			
DROP TABLE [<xsl:value-of select="$Name"/>_<xsl:value-of select="Name"/>]
GO

			
CREATE TABLE [<xsl:value-of select="$Name"/>_<xsl:value-of select="Name"/>] (
	[<xsl:value-of select="$Name"/>ID] [uniqueidentifier] NOT NULL,
	[<xsl:value-of select="Type"/>bID] [uniqueidentifier] NOT NULL,
	CONSTRAINT [PK_<xsl:value-of select="$Name"/>_<xsl:value-of select="Name"/>] PRIMARY KEY CLUSTERED (
		[<xsl:value-of select="$Name"/>ID],	
		[<xsl:value-of select="Type"/>bID]
	) ON [PRIMARY]
) ON [PRIMARY]	
GO
			</xsl:if>
		</xsl:for-each>

		
	</xsl:template>
</xsl:stylesheet>